import router from './index'
import { useUserStore } from '../stores/user'

// 需要登录才能访问的路由
const authRoutes = ['/order', '/payment', '/deliveryAddress', '/orderList']

router.beforeEach((to, from, next) => {
  const userStore = useUserStore()
  
  if (authRoutes.includes(to.path) && !userStore.isLoggedIn()) {
    next({
      path: '/login',
      query: { redirect: to.fullPath }
    })
  } else {
    next()
  }
}) 